<script lang="ts">
import type { VNode } from 'vue'
import { omit } from 'lodash-es'
import type { TableScopedColumn } from '@/types'

interface Props<T, U> {
  render: (scoped?: { row: T, column: U, index: number }) => VNode | string
  row: T
  column: U
  index: number
}
export default defineComponent(
  <T = Record<string, any>, U = TableScopedColumn>(props: Props<T, U>) => {
    // ! 解决h函数(tsx)首次渲染触发绑定事件问题
    const [isFirst, setIsFirst] = useState<boolean>(false)
    // 两种方法都可
    // onMounted(() => {
    //   setIsFirst(true);
    // });
    nextTick(() => {
      setIsFirst(true)
    })
    return () => unref(isFirst) && props?.render?.(omit(props, 'render'))
  },
  {
    // eslint-disable-next-line
    props: ['render', 'row', 'column', 'index']
  },
)
</script>
